package com.qidian.mes.dv.service.impl;

import com.qidian.mes.dv.mapper.DvMachineryTypeMapper;
import com.qidian.mes.dv.service.DvMachineryTypeService;
import com.qidian.mes.pojo.DvMachineryType;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DvMachineryTypeServiceImpl implements DvMachineryTypeService {
    @Autowired
    DvMachineryTypeMapper dvMachineryTypeMapper;

    @Override
    //查询数据返回数
    public MESResult listTree() {
        List<DvMachineryType> list=list(0L);
        return MESResult.ok(list);
    }

    @Override
    //根据父节点递归查询数据
    public List<DvMachineryType> list(Long parentTypeId) {
        List<DvMachineryType> dvMachineryTypes = dvMachineryTypeMapper.list(parentTypeId);
        for (DvMachineryType dvMachineryType : dvMachineryTypes) {
            if (dvMachineryType.getAncestors().equals(1)) {
                // 有子权限，递归查询
                dvMachineryType.setChildren(list(dvMachineryType.getMachineTypeId()));
            }
        }
        return dvMachineryTypes;
    }
}
